package hsb.ruoyi.admin.web.controller.system;

import hsb.ruoyi.common.annotation.Log;
import hsb.ruoyi.common.core.controller.BaseController;
import hsb.ruoyi.common.core.domain.AjaxResult;
import hsb.ruoyi.common.core.page.TableDataInfo;
import hsb.ruoyi.common.enums.BusinessType;
import hsb.ruoyi.system.domain.SysNotice;
import hsb.ruoyi.system.service.ISysNoticeService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.List;
/**
 * 公告 信息操作处理
 *
 * @author ruoyi
 */
@Produces(MediaType.APPLICATION_JSON)
@Path("/system/notice")
public class SysNoticeController extends BaseController {
    @Autowired
    private ISysNoticeService noticeService;

    /**
     * 获取通知公告列表
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:list')")
    @GET
    @Path("/list")
    public TableDataInfo list(@BeanParam SysNotice notice) {
        startPage();
        List<SysNotice> list = noticeService.selectNoticeList(notice);
        return getDataTable(list);
    }

    /**
     * 根据通知公告编号获取详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:query')")
    @GET
    @Path(value = "/{noticeId}")
    public AjaxResult getInfo(@PathParam("noticeId") Long noticeId) {
        return AjaxResult.success(noticeService.selectNoticeById(noticeId));
    }

    /**
     * 新增通知公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @POST
    public AjaxResult add(@Valid SysNotice notice) {
        notice.setCreateBy(getUsername());
        return toAjax(noticeService.insertNotice(notice));
    }

    /**
     * 修改通知公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PUT
    public AjaxResult edit(@Valid SysNotice notice) {
        notice.setUpdateBy(getUsername());
        return toAjax(noticeService.updateNotice(notice));
    }

    /**
     * 删除通知公告
     */
    //@PreAuthorize("@ss.hasPermi('system:notice:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DELETE
    @Path("/{noticeIds}")
    public AjaxResult remove(@PathParam("noticeIds") Long[] noticeIds) {
        return toAjax(noticeService.deleteNoticeByIds(noticeIds));
    }
}
